package com.liuwei.spring.cloud.controller;

import com.fasterxml.jackson.databind.node.JsonNodeFactory;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.liuwei.spring.cloud.biz.service.LiLogService;
import com.liuwei.spring.cloud.biz.service.MockService;
import com.liuwei.spring.cloud.framework.dto.Result;
import com.liuwei.spring.cloud.common.utils.DateHelper;
import com.liuwei.spring.cloud.common.utils.Jackson;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.List;

/**
 * @author : MainController
 * @version V1.0
 * @date: 2023/12/23 12:19 AM
 * @Description: TODO
 */
@Slf4j
@RestController
@RequestMapping("/api")
@Tag(name = "Main 模拟数据接口")
public class MainController {

    @Resource
    MockService iMockService;

    @Resource
    LiLogService iLiLogService;

    @Value("${application.author.name:}")
    private String application_author_name;

    @GetMapping("/index")
    public String index() {
        log.info("application.author.name #{}#", application_author_name);
        ObjectNode creator = JsonNodeFactory.instance.objectNode();
        creator.put("name", "liuwei");
        creator.put("time", DateHelper.formatNosplit24Second(new Date()));
        log.info(Jackson.toJSONString(creator));
        String value =
                """
                        this is 
                        liuwei
                        """;
        log.info(value);
        return Jackson.toJSONString(creator);
    }

    @GetMapping("/mock")
    public String mock(@RequestParam("name") String name) throws InterruptedException {
        return iMockService.mock(name);
    }

    @GetMapping("/collection")
    public String collection(@RequestParam("names") List<String> names) throws InterruptedException {
        return iMockService.collection(names);
    }

    @GetMapping("/log/http")
    public Result http(String env, String cluster, String provider) throws InterruptedException {
        iLiLogService.syncHttpLog(env, cluster, provider);
        return Result.success();
    }

    @GetMapping("/log/file")
    public Result file(String env, String cluster, String provider, String filePath) throws InterruptedException {
        iLiLogService.syncFileLog(env, cluster, provider, filePath);
        return Result.success();
    }


}
